import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter as Router} from 'react-router-dom'

import {IntlProvider, addLocaleData} from 'react-intl';
import zh from 'react-intl/locale-data/zh';//react-intl语言包
import en from 'react-intl/locale-data/en';//react-intl语言包
import zh_CN from '../i18n/zh-CN';//个人配置
import en_US from '../i18n/en-US';//个人配置
import intl from 'intl';

addLocaleData([...en, ...zh]);

import store from './Redux'
import {Provider} from 'react-redux'

import Header from './components/header';
import Content from './components/content';
import Footer from "./components/footer";

class App extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            links: ['登录', '注册'],
            system: {name: '****Cloud', desc: 'Aisino Hyper-conveged system'},
            user: {name: '注册试用'},
        };
    }

    render() {
        return (
            <div>
                <Header links={this.state.links} system={this.state.system} user={this.state.user}></Header>
                <Content></Content>
                <Footer></Footer>
            </div>
        )
    }
}

function chooseLocale() {
    console.log(navigator.language.split('-')[0])
    switch (navigator.language.split('-')[0]) {
        case 'en':
            return en_US;
            break;
        case 'zh':
            return zh_CN;
            break;
        default:
            return en_US;
            break;
    }
}

ReactDOM.render(
    <Provider store={store}>
        <IntlProvider locale={navigator.language} messages={chooseLocale()}>
            <Router>
                <App></App>
            </Router>
        </IntlProvider>
    </Provider>,
    document.getElementById('app')
);
